package org.jetlinks.pro.things;

import org.jetlinks.core.message.ThingMessage;
import org.jetlinks.pro.things.impl.converter.ExpressionThingMessageConverter;
import reactor.core.publisher.Mono;

import java.util.Map;


/**
 * 物消息转换器,将消息模版和上下文转为新的消息
 *
 * @author zhouhao
 * @since 1.12
 */
public interface ThingMessageConverter {

    /**
     * 转换消息
     *
     * @param context  上下文
     * @param template 模版
     * @return 新的消息
     */
    Mono<ThingMessage> convert(Map<String, Object> context, ThingMessage template);

    static ThingMessageConverter identity() {
        return (ctx, msg) -> Mono.just(msg);
    }

    static ThingMessageConverter expression() {
        return ExpressionThingMessageConverter.INSTANCE;
    }

}
